import request from '@/utils/http'
import { LOGIN_API_URL } from '@/config/api'

interface LoginResult {
  access_token: string
  expires_in: number
  token_type: string
  refresh_token: string
  scope: string
}

interface UserInfoResult {
  isAuthenticated: boolean
  id: string
  userName: string
  name: any
  surName: any
  phoneNumber: any
  phoneNumberVerified: boolean
  email: string
  emailVerified: boolean
  tenantId: string
  roles: string[]
}

export function loginAndToken(data) {
  return request.request<LoginResult>({
    baseURL: LOGIN_API_URL,
    url: '/connect/token',
    method: 'post',
    data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    showErrorMessage: false
  })
}

// 获取登录人的基本信息
export function getHuoQuRenYuanJiBenXinXi() {
  return request.request<UserInfoResult>({
    url: '/api/identity/GetUserInfoByToken',
    method: 'get'
  })
}

// // 根据登录token信息获取前端页面租户名称相关显示
// export function getHuoQuZuHuName() {
//   return request_3({
//     url: '/api/v3.0/basic/tenant-related-page',
//     method: 'get'
//   })
// }

// // 根据二级域名获取前端页面租户名称相关显示
// export function getGenJuErJiYuMingHuoQuZuHuMingCheng(domainName) {
//   return request22({
//     url: '/api/v3.0/basic/tenant-related-page/by-domain-name?domainName=' + domainName,
//     method: 'get'
//   })
// }

// // 查询首页数据装饰
// export function getKeShiHuaYeMianZhuangShi() {
//   return request_3({
//     url: '/api/v3.0/basic/data-config/with-date-by-tenant',
//     method: 'get'
//   })
// }

// // 获取所有工序
// export function getSuoYouGongXu() {
//   return request_3({
//     url: 'api/v3.0/basic/craft-node',
//     method: 'get'
//   })
// }
